//
//  DiscoverViewController.swift
//  FWSinaWeibo
//
//  Created by 范伟 on 16/2/21.
//  Copyright © 2016年 FanWei. All rights reserved.
//

import UIKit
private let reuseID = "DiscoverCell"

class DiscoverViewController: RootViewController {

    override func viewDidLoad() {
        initRefreshControl()
        super.viewDidLoad()
        visitorView?.setupInformation("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        //注册cell
        tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: reuseID)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    private var dataCount = 0
    
    override func loadData() {
        refreshControl?.beginRefreshing()
        /**
         参数
         1. 现在
         2. 时间差：纳秒／秒
         */
        let when = dispatch_time(DISPATCH_TIME_NOW, Int64(Double(NSEC_PER_MSEC) * 1.0))
        dispatch_after(when, dispatch_get_main_queue()) {
            self.dataCount += 10
            self.refreshControl?.endRefreshing()
            self.tableView?.reloadData()
        }
    }
}
// MARK: - UITableViewDataSource
extension DiscoverViewController {
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataCount
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(reuseID, forIndexPath: indexPath)
        cell.textLabel?.text = indexPath.row.description
        return cell
    }
}
